#pragma once
#include "../SockLib/NetMan.h"

#define STRLEN 255
#define YES TRUE
#define NO FALSE

#define WM_TRAY WM_USER
#define WM_CONNECTION_FAIL WM_USER+1
#define WM_CONNECTION_UP WM_USER+2

#define ERR_TRAY_NOT_CREATED 1
#define UPDATING_TIME 1000
#define ECHO_TIME 1500
#define RECONNECT_TIME 2000

typedef unsigned int uint;
struct MonitoredItem;
struct MonitoringDataBase;
struct PingedItem;
struct Report;

extern HWND hWndClient;
extern uint ClientId;
extern MonitoringDataBase database;
extern Report new_report;
extern TCPMan	ManagerTCP;
extern bool IsConnected;

TCPConnection *ClientFabric(TCPMan *pManager, TCPServer *pServer, const char *szAddress, WORD wPort);

class ClientConnection: public TCPConnectionPackets
{
public:
	ClientConnection(const char *szAddress, WORD wPort, TCPMan *pManager):
	  TCPConnectionPackets(szAddress, wPort, pManager){;};
	uint ID;

protected:
	virtual void OnPack(const char *pPacket, unsigned short int wSize);
	virtual void OnConnect();
	virtual void OnDisconnect();
	virtual void OnError(long lError, const char *szErrorDesc);
};

struct MonitoredItem
{
	uint id;
	char *url;
	uint urlsize;
	ClientConnection *connection;

	MonitoredItem();
	MonitoredItem(const MonitoredItem &mi);
	~MonitoredItem();

	void Set(uint i, char *u, uint s);
	void Clear();
	MonitoredItem& operator = (const MonitoredItem &mi);
};

struct MonitoringDataBase
{
	uint interval; //sec
	MonitoredItem *item;
	uint itemcount;
	bool fInit;

	MonitoringDataBase();
	~MonitoringDataBase();

	void Clear();
};

struct PingedItem
{
	uint id;
	uint ping; //msec
	bool fpinged;
};

struct Report
{
	time_t sttime;
	PingedItem *item;
	uint itemcount;

	Report();
	~Report();

	void Clear();
	bool Save(char *filename, int len);
	bool Load(char *filename, int len);
};